<template>
  <div class="dashboard-content">
    <!-- 数据统计卡片 -->
    <el-row :gutter="20" class="stats-row">
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-info">
              <div class="stat-title">总数据量</div>
              <div class="stat-value">{{ formatNumber(12580) }}</div>
              <div class="stat-trend">
                <el-icon color="#67C23A"><CaretTop /></el-icon>
                <span class="trend-text">12.5%</span>
              </div>
            </div>
            <div class="stat-icon" style="background: #409EFF20;">
              <el-icon :size="40" color="#409EFF"><DataLine /></el-icon>
            </div>
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-info">
              <div class="stat-title">热搜关键词</div>
              <div class="stat-value">{{ formatNumber(3568) }}</div>
              <div class="stat-trend">
                <el-icon color="#67C23A"><CaretTop /></el-icon>
                <span class="trend-text">8.3%</span>
              </div>
            </div>
            <div class="stat-icon" style="background: #67C23A20;">
              <el-icon :size="40" color="#67C23A"><TrendCharts /></el-icon>
            </div>
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-info">
              <div class="stat-title">AI分析任务</div>
              <div class="stat-value">{{ formatNumber(856) }}</div>
              <div class="stat-trend">
                <el-icon color="#E6A23C"><CaretBottom /></el-icon>
                <span class="trend-text">3.2%</span>
              </div>
            </div>
            <div class="stat-icon" style="background: #E6A23C20;">
              <el-icon :size="40" color="#E6A23C"><MagicStick /></el-icon>
            </div>
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="stat-card" shadow="hover">
          <div class="stat-content">
            <div class="stat-info">
              <div class="stat-title">活跃用户</div>
              <div class="stat-value">{{ formatNumber(245) }}</div>
              <div class="stat-trend">
                <el-icon color="#67C23A"><CaretTop /></el-icon>
                <span class="trend-text">15.7%</span>
              </div>
            </div>
            <div class="stat-icon" style="background: #F56C6C20;">
              <el-icon :size="40" color="#F56C6C"><User /></el-icon>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 图表区域 -->
    <el-row :gutter="20" class="chart-row">
      <el-col :xs="24" :md="16">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>数据趋势分析</span>
              <el-radio-group v-model="chartPeriod" size="small">
                <el-radio-button label="week">本周</el-radio-button>
                <el-radio-button label="month">本月</el-radio-button>
                <el-radio-button label="year">本年</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-placeholder">
            <el-icon :size="60" color="#ddd"><DataLine /></el-icon>
            <p>数据趋势图表（待集成图表库）</p>
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :md="8">
        <el-card>
          <template #header>
            <span>热搜排行榜</span>
          </template>
          <div class="ranking-list">
            <div v-for="(item, index) in hotRankings" :key="index" class="ranking-item">
              <div class="ranking-index" :class="'rank-' + (index + 1)">{{ index + 1 }}</div>
              <div class="ranking-content">
                <div class="ranking-title">{{ item.title }}</div>
                <div class="ranking-count">{{ formatNumber(item.count) }} 次</div>
              </div>
              <el-tag :type="item.trend === 'up' ? 'danger' : 'info'" size="small">
                {{ item.trend === 'up' ? '热' : '新' }}
              </el-tag>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 快速操作和系统信息 -->
    <el-row :gutter="20">
      <el-col :xs="24" :md="12">
        <el-card>
          <template #header>
            <span>快速操作</span>
          </template>
          <div class="quick-actions">
            <el-button type="primary" :icon="Upload">数据导入</el-button>
            <el-button type="success" :icon="Download">数据导出</el-button>
            <el-button type="warning" :icon="RefreshRight">刷新数据</el-button>
            <el-button type="info" :icon="Setting">系统配置</el-button>
          </div>
        </el-card>
      </el-col>

      <el-col :xs="24" :md="12">
        <el-card>
          <template #header>
            <span>系统信息</span>
          </template>
          <el-descriptions :column="1" border>
            <el-descriptions-item label="系统版本">v1.0.0</el-descriptions-item>
            <el-descriptions-item label="数据库">PostgreSQL 16.3</el-descriptions-item>
            <el-descriptions-item label="后端框架">Django 4.2.7</el-descriptions-item>
            <el-descriptions-item label="前端框架">Vue 3 + Element Plus</el-descriptions-item>
          </el-descriptions>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  User,
  TrendCharts,
  MagicStick,
  CaretTop,
  CaretBottom,
  DataLine,
  Upload,
  Download,
  RefreshRight,
  Setting
} from '@element-plus/icons-vue'

const chartPeriod = ref('week')

// 热搜排行榜数据
const hotRankings = ref([
  { title: 'AI技术发展趋势', count: 156800, trend: 'up' },
  { title: '数据安全与隐私保护', count: 128900, trend: 'up' },
  { title: '云计算服务优化', count: 98700, trend: 'new' },
  { title: '机器学习算法应用', count: 87600, trend: 'up' },
  { title: '大数据分析平台', count: 76500, trend: 'new' }
])

// 格式化数字
const formatNumber = (num) => {
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
</script>

<style scoped>
.dashboard-content {
  padding: 20px;
}

/* 统计卡片 */
.stats-row {
  margin-bottom: 24px;
}

.stat-card {
  height: 100%;
}

.stat-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-info {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.stat-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
}

.trend-text {
  color: #67C23A;
}

.stat-icon {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 图表区域 */
.chart-row {
  margin-bottom: 24px;
}

.chart-placeholder {
  height: 350px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #999;
}

.chart-placeholder p {
  margin-top: 12px;
  font-size: 14px;
}

/* 热搜排行榜 */
.ranking-list {
  max-height: 350px;
  overflow-y: auto;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.3s;
}

.ranking-item:hover {
  background-color: #f5f7fa;
}

.ranking-item:last-child {
  border-bottom: none;
}

.ranking-index {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f0f0;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
}

.ranking-index.rank-1 {
  background-color: #f56c6c;
  color: white;
}

.ranking-index.rank-2 {
  background-color: #e6a23c;
  color: white;
}

.ranking-index.rank-3 {
  background-color: #409eff;
  color: white;
}

.ranking-content {
  flex: 1;
}

.ranking-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
}

.ranking-count {
  font-size: 12px;
  color: #999;
}

/* 快速操作 */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* 卡片头部 */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

/* 响应式 */
@media (max-width: 768px) {
  .stat-value {
    font-size: 24px;
  }

  .stat-icon {
    width: 60px;
    height: 60px;
  }
}
</style>

